package com.example.ktapplication.activity

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.view.isGone
import com.bumptech.glide.Glide
import com.example.ktapplication.R
import com.example.ktapplication.base.BaseActivity
import com.example.ktapplication.bean.SysBlogList
import com.example.ktapplication.databinding.ActivitySysBlogBinding
import com.example.ktapplication.fragment.SysTabFragment
import com.example.ktapplication.utils.toJson

class SysBlogListActivity : BaseActivity<ActivitySysBlogBinding>() {

    private val data by lazy {
        intent?.getStringExtra(EXTRA_DATA) ?: ""
    }

    private val title by lazy {
        intent?.getStringExtra(EXTRA_TITLE) ?: ""
    }

    private val sysTabFragment by lazy {
        SysTabFragment(data)
    }

    companion object {
        private const val EXTRA_DATA = "data"
        private const val EXTRA_TITLE = "title"

        fun start(context: Context, data: SysBlogList) {
            val intent = Intent(context, SysBlogListActivity::class.java)
            intent.putExtra(EXTRA_DATA, data.toJson())
            intent.putExtra(EXTRA_TITLE, data.data.name)
            context.startActivity(intent)
        }
    }

    override fun getViewBind(): ActivitySysBlogBinding {
        return ActivitySysBlogBinding.inflate(layoutInflater)
    }

    override fun onDate(savedInstanceState: Bundle?) {
    }

    @SuppressLint("ResourceType")
    override fun onViewBing() {
        initTitleBar()
        showFragment(sysTabFragment, R.id.statusLayout)
    }

    private fun initTitleBar() {
        binding.titleBar.tvTitle?.text = title
        binding.titleBar.imgMenu?.apply {
            Glide.with(context)
                .load(R.mipmap.left)
                .into(this)
            setOnClickListener {
                finish()
            }
        }
        binding.titleBar.imgFind?.isGone = true
    }


}